package com.sto.stoapp.activity.scanner;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.adapter.InquiryMenuAdapter;
import com.sto.stoapp.broadcast.HomeBroadAction;
import com.sto.stoapp.entity.InquiryEntity;
import com.sto.stoapp.status.EnumTableNames;
import com.sto.stoapp.status.OperateEnumTable;
import com.sto.stoapp.widget.StoHomeActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author Administrator
 * 
 */
public class ErrorRecordActivity extends StoHomeActivity {
	private String action;

	ListView listView;
	List<EnumTableNames> tableNames = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.sto_inquirymenu_list);
		Bundle extras = getIntent().getExtras();
		action = extras.getString("busiType");
		this.setTitleBottom(R.string.error_upload, action);
		initView();
	}

	private void initView() {
		listView = (ListView) findViewById(R.id.dest_list);

		if (HomeBroadAction.AVIATION_BROAD.equals(action)) {
			tableNames = OperateEnumTable.getAviationTables();
		} else if (HomeBroadAction.CENTER_BROAD.equals(action)) {
			tableNames = OperateEnumTable.getCenterTables();
		} else if (HomeBroadAction.SCANNER_MAN_BROAD.equals(action)) {
			tableNames = OperateEnumTable.getScannerTables();
		} else if (HomeBroadAction.SALES_MAN_BROAD.equals(action)) {
			tableNames = OperateEnumTable.getSaleTables();
		} else {
			tableNames = OperateEnumTable.getAllTables();
		}
		ArrayList<InquiryEntity> names = new ArrayList<InquiryEntity>();

		for (EnumTableNames name : tableNames) {
			InquiryEntity inquiryEntity = new InquiryEntity();
			inquiryEntity.setMenuName(getString(Integer.parseInt(name
					.getScanTypeName())));
			inquiryEntity.setImageId(R.drawable.next);
			names.add(inquiryEntity); // 保存了所有的数据行

		}
		InquiryMenuAdapter menuAdapter = new InquiryMenuAdapter(this, names);
		listView.setAdapter(menuAdapter);

		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {

				turnTo(tableNames.get(position));
			}
		});
	}

	private void turnTo(EnumTableNames name) {
		Intent intent = new Intent(this, ErrorRecordInfoActivity.class);
		intent.putExtra("busiType", action);
		intent.putExtra("EnumTableNames", name);
		startActivity(intent);
	}
}
